home *** CD-ROM | disk | FTP | other *** search
/ Maplin Electronics Catalogue 2001 Winter / Maplins Catalogue Winter 2001.iso / JScript / OrderF.js < prev    next >
Text File  |  2001-11-28  |  30KB  |  836 lines

  1. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  2. // *     CustDetail.js JavaScript Development by Burgeonet.com           * 
  3. // *                Development Started 12-10-2000                       *
  4. // * This File should be linked to PrintFile.js in the controlling page  *
  5. // *   Functions with descriptions surrounded with "*=*=*=*" are tested  * 
  6. // *                       complete and bug free                          *
  7. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  8.  
  9. // **********************************************************************
  10. // * ToDo:
  11. // * 
  12. // * 
  13. // *  
  14. // * 
  15.         
  16. // * Progress:
  17. // * routine to create unique name for form and index.
  18. // * Routine to create the details cookie
  19. // * routine to create index
  20. // * routine to save the form with index name
  21. // * routine to display index
  22. // * routine to select saved form from the index 
  23. // * 
  24. // * 
  25. // * 
  26. // * 
  27. // *         
  28. // **********************************************************************
  29.  
  30. // ---====**** Begin code section for Customer Detail display ****====---
  31.  
  32. // **********************************************************************
  33. // * Establish array variables. These must match the                     *
  34. // * Customer Detail Variables as per the CustDetail.htm page.            *
  35. // *                                                                     *
  36. // *  Customer Number       CustNumber                                  *
  37. // *  Account Number        AccNumber                                      *
  38. // *  Mr/Mrs/Miss/Ms        Salute                                         *
  39. // *  First name            FirstName                                     *
  40. // *  Initials                Initials                                     *
  41. // *  Last Name                LastName                                     *
  42. // *  Company Name            Comp Name                                     *
  43. // *  Address                Address                                         *
  44. // *  Address2                Address2                                     *
  45. // *  Post Code                PoCode                                         *
  46. // *  Telephone                CustTele                                    *
  47. // *                                                                     *
  48. // *                             1 2 3 4 5 6 7 8 9 10 11 12 13 14           *
  49. // *   Delimitor characters     ñ ª º ½ ¼ ║ ╗ ┐ ╢  ▐     °  ^  ó           *
  50. // *                                                                    *
  51. // **********************************************************************
  52.  
  53. // ** global variables for the orderform.**  
  54.  
  55. var CustNumber     = new Array();
  56. var AccNumber     = new Array();
  57. var Salute        = new Array();
  58. var FirstName    = new Array();
  59. var Initials    = new Array();
  60. var LastName    = new Array();
  61. var CompName    = new Array();
  62. var Address        = new Array();
  63. var Address2    = new Array();
  64. var PoCode        = new Array();
  65. var CustTele    = new Array();
  66.  
  67. // ** global variables for the shopping cart.**
  68. var counterA
  69. var itemNum = new Array();
  70. var itemDescr = new Array();
  71. var itemCost = new Array();
  72. var itemQty = new Array();
  73.  
  74. //            ----====**** Global variables. ****====----
  75.  
  76. var formIndex = new Array();
  77. var counter = 0
  78. var counterA = 0
  79. var cookData = ""
  80. var idxData = ""
  81. var formName = "form"
  82. var expdate2 = new Date();
  83.  
  84.  
  85. // -----------------------------  End  ----------------------------------
  86.  
  87. //          ----====****Begin shared cookie functions****====----
  88.  
  89. // **********************************************************************
  90. // *            Global expdate variable for cookies                        *
  91. // *               Cookie is set to expire in 1 year                    *
  92. // **********************************************************************
  93.  
  94. var expdate = new Date();
  95. expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000))
  96.  
  97. // -----------------------------  End  ----------------------------------
  98.  
  99. // **********************************************************************
  100. // *                        Read cookie data.                           *
  101. // **********************************************************************
  102.  
  103. function getCookieData(name) {
  104.  var label = name + "="
  105.  var cStart = document.cookie.indexOf(label) 
  106.  if (cStart != -1) {  // If the cookie does not exist skip the load
  107.  var labelLen = label.length
  108.  var cLen = document.cookie.length
  109.  cStart += labelLen
  110.  var tempstr = document.cookie.substring(cStart,cLen)
  111.  var cEnd = tempstr.indexOf(";")
  112.          if (cEnd == -1) {
  113.              cEnd = document.cookie.length
  114.         }
  115.   return unescape(tempstr.substring(0,cEnd))
  116.  }
  117.  return""
  118. }
  119. // -----------------------------  End  ----------------------------------
  120.  
  121.  
  122. // **********************************************************************
  123. // *                        Write cookie data.                            *
  124. // **********************************************************************
  125.  
  126. function setCookieData(name,value,expires) {
  127.         counter ++ 
  128.     document.cookie = name + "=" + counter + "@" + value + "; expires=" 
  129.                    + expires + "; Path=" + "/"
  130. }
  131.  
  132. // -----------------------------  End  ----------------------------------
  133.  
  134.  
  135. // **********************************************************************
  136. // *                     Kill cookie function.                          *
  137. // **********************************************************************
  138.  
  139. function killCookie(name) {
  140.  if (getCookieData(name)) {
  141.  document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT" + ";path = /"
  142.  cookData = ""
  143.  counter = 0
  144. history.go(0)
  145.  }
  146. }
  147.  
  148. // -----------------------------  End  ----------------------------------
  149.  
  150. //          ----====**** End shared cookie functions ****====----
  151.  
  152. // **********************************************************************
  153. // *               Begin code section to update the cookie to           *
  154. // *              add items to the shopping cart cookie 'Scart'.        *
  155. // **********************************************************************
  156.  
  157.  
  158.  
  159. // **********************************************************************
  160. // *           Extract current value of cookie when page loads          *
  161. // *            and store the values in the global variables.           *
  162. // **********************************************************************
  163.  
  164. if (getCookieData(name)) {
  165.  
  166.  orderString = getCookieData(name)
  167.  cLen = orderString.length
  168.  countEnd = orderString.indexOf("@")
  169.  pointer = countEnd + 1
  170.  counter = orderString.substring(0,countEnd)
  171.  cookData = orderString.substring(pointer,cLen)
  172. }
  173.  
  174. // -----------------------------  End  ----------------------------------
  175.  
  176. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  177. // *        Function to add details to the Details Cookie.               *
  178. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  179.  
  180. function addDetails() {
  181. counter = 0
  182. detailInfo = '' + CustNumber + '~' + AccNumber + 'ª' + Salute + '¼' + FirstName 
  183.         + '║' + Initials + '╗' + LastName + '┐' + CompName + '╢' + Address + '▐' + Address2 
  184.         + ' ' + PoCode + '°' +  CustTele  + '^'
  185.  
  186. cookData = eval("detailInfo")
  187. setCookieData("Detail", cookData, expdate.toGMTString())
  188. }
  189.  
  190. // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*= End *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  191.  
  192.  
  193.  
  194. //  ----====**** End code section for updating the cookie. ****====----
  195.  
  196. // **********************************************************************
  197. // *            Builds an array of the items to load the form.          *
  198. // **********************************************************************
  199.  
  200. function formDetail(Idx,Cus,Acn,Sal,Fir,Ini,Lnm,Com,Adda,Addb,Pcde,Ctel) {
  201.  
  202. CustNumber[Idx]    = Cus
  203. AccNumber[Idx]    = Acn
  204. Salute[Idx]        = Sal
  205. FirstName[Idx]    = Fir    
  206. Initials[Idx]    = Ini    
  207. LastName[Idx]    = Lnm    
  208. CompName[Idx]    = Com    
  209. Address[Idx]    = Adda        
  210. Address2[Idx]    = Addb    
  211. PoCode[Idx]        = Pcde        
  212. CustTele[Idx]    = Ctel    
  213.  
  214. }
  215. // -----------------------------  End  ----------------------------------
  216.  
  217. // **********************************************************************
  218. // *            Builds an array of the items to load into the form.     *
  219. // **********************************************************************
  220.  
  221. function orderDetail(seq,num,descr,cost,Qty) {
  222.  itemNum[seq]   = num
  223.  itemDescr[seq] = descr
  224.  itemCost[seq]  = cost
  225.  itemQty[seq]  = Qty
  226. }
  227. // -----------------------------  End  ----------------------------------
  228.  
  229. // **********************************************************************
  230. // *    Function to parse the cookie and extract the ordered            *
  231. // *                    items from the string.                           *
  232. // **********************************************************************
  233.  
  234. function itemsOrdered() {
  235.  if (getCookieData("Scart")) {
  236.  substr0 = getCookieData("Scart")
  237.  cLen = substr0.length
  238.  offset0 = substr0.indexOf("@")
  239.  
  240.  counter = substr0.substring(0,offset0)
  241.  
  242.  j = 0
  243.   for (i=1; i<=counter; i++) {
  244.   offsetq = eval('offset' + j + '');
  245.   substrq = eval('substr' + j + '');
  246.  
  247.   eval('ind' + i + ' = offsetq + 1');
  248.   eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  249.   eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  250.   eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  251.  
  252.   eval('catInd' + i + ' = item' + i + '.indexOf("`")');
  253.   eval('itemCat' + i + ' = item' + i + '.substring(0,catInd' + i + ')');
  254.  
  255.   eval('descrInd' + i + ' = item' + i + '.indexOf("~")');
  256.   eval('itemDes' + i + ' = item' + i + '.substring((catInd' + i + ' + 1),descrInd' + i + ')');
  257.  
  258.   eval('priceInd' + i + ' = item' + i + '.indexOf("½")');
  259.   eval('itemPr' + i + ' = item' + i + '.substring((descrInd' + i + ' + 2),priceInd' + i + ')'); 
  260.   
  261.   eval('itemQt' + i + ' = item' + i + '.substring((priceInd' + i + ' + 1),offset' + i + ')'); 
  262.   eval('orderDetail(i,itemCat' + i + ',itemDes' + i + ',itemPr' + i + ',itemQt' + i +')');
  263.  
  264.   j++
  265.   }
  266.  }
  267. }
  268. // -----------------------------  End  ----------------------------------
  269.  
  270. // **********************************************************************
  271. // *    Function to parse the cookie and extract the form details       *
  272. // *        items from the string. This in turn triggers the            *
  273. // *    writeDetails() function to display the form.                    *
  274. // **********************************************************************
  275.  
  276.  
  277. function DetailsStored() {
  278.  
  279. //addDetail = '' AccNumber + '~' + AccNumber + 'ª' + Salute + '¼' + FirstName 
  280. //+ '║' + Initials + '╗' + LastName + '┐' + CompName + '╢' + Address + '▐' + Address2 
  281. //+ ' ' + PoCode + '°' +  CustTele
  282.  
  283.  
  284. if (getCookieData("Detail")) {
  285.  substr0 = getCookieData("Detail")
  286.  cLen = substr0.length
  287.  offset0 = substr0.indexOf("@")
  288.  counter = substr0.substring(0,offset0)
  289.  counterA = counter //====used in form ====??? is it needed or can we just use counter
  290.  j = 0
  291.   for (i=1; i<=counter; i++) {
  292.   offsetq = eval('offset' + j + '');
  293.   substrq = eval('substr' + j + '');
  294.  
  295.   eval('ind' + i + ' = offsetq + 1');
  296.   eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  297.   eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  298.   eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  299.  
  300.  // Customer Number
  301.   eval('CusInd' + i + ' = item' + i + '.indexOf("~")');
  302.   eval('Cus' + i + ' = item' + i + '.substring(0,CusInd' + i + ')');
  303.  
  304.   // Account Number
  305.    eval('AccInd' + i + ' = item' + i + '.indexOf("ª")');
  306.    eval('Acc' + i + ' = item' + i + '.substring((CusInd' + i + ' + 1),AccInd' + i + ')');
  307.   
  308.   // Salutation
  309.   eval('SalutInd' + i + ' = item' + i + '.indexOf("¼")');
  310.   eval('Salut' + i + ' = item' + i + '.substring((AccInd' + i + ' + 1),SalutInd' + i + ')');
  311.  
  312.  // First Name
  313.   eval('FirstInd' + i + ' = item' + i + '.indexOf("║")');
  314.   eval('FirstNam' + i + ' = item' + i + '.substring((SalutInd' + i + ' + 1),FirstInd' + i + ')');
  315.  
  316.  // Initials
  317.   eval('InitialInd' + i + ' = item' + i + '.indexOf("╗")');
  318.   eval('Initials' + i + ' = item' + i + '.substring((FirstInd' + i + ' + 1),InitialInd' + i + ')');
  319.   
  320. // Last Name
  321.   eval('LastNamInd' + i + ' = item' + i + '.indexOf("┐")');
  322.   eval('LastNam' + i + ' = item' + i + '.substring((InitialInd' + i + ' + 1),LastNamInd' + i + ')'); 
  323.  
  324. // Company Name
  325.   eval('CompNamInd' + i + ' = item' + i + '.indexOf("╢")');
  326.   eval('CompNam' + i + ' = item' + i + '.substring((LastNamInd' + i + ' + 1),CompNamInd' + i + ')'); 
  327.  
  328. // Address
  329.   eval('AddInd' + i + ' = item' + i + '.indexOf("▐")');
  330.   eval('Add' + i + ' = item' + i + '.substring((CompNamInd' + i + ' + 1),AddInd' + i + ')'); 
  331.  
  332. // Address2
  333.   eval('Add2Ind' + i + ' = item' + i + '.indexOf(" ")');
  334.   eval('Add2' + i + ' = item' + i + '.substring((AddInd' + i + ' + 1),Add2Ind' + i + ')'); 
  335.  
  336. // Postal Code
  337.   eval('PoCdeInd' + i + ' = item' + i + '.indexOf("°")');
  338.   eval('PoCde' + i + ' = item' + i + '.substring((Add2Ind' + i + ' + 1),PoCdeInd' + i + ')'); 
  339.  
  340.   // Telephone
  341.   eval('CustTel' + i + ' = item' + i + '.substring((PoCdeInd' + i + ' + 1),offset' + i + ')'); 
  342.  
  343.  eval('formDetail(i,Cus' + i + ',Acc' + i + ',Salut' + i + ',FirstNam' + i + ',Initials' + i + ',LastNam' + i +',CompNam' + i + ',Add' + i +',Add2' + i +',PoCde' + i +',CustTel' + i +')');
  344.  
  345. j++
  346.  
  347.  }
  348.  
  349.  }
  350. }
  351.  
  352. function showForm() {
  353. WriteDetails();
  354. }
  355. // ------------------------  End Cookie Reader ------------------
  356.  
  357. //                   ----====**** $$$ ****====----
  358.  
  359.  
  360. //     ----====**** End Customer Detail cookie code. ****====----
  361.  
  362.  
  363.  
  364. // ****Start of code section for calculations****
  365.  
  366. function update() {
  367.  if (getCookieData("Scart")) {
  368.   var sub_total = 0;
  369.   for (i=1; i<itemNum.length; i++)
  370.    eval('sub_total += parseFloat(itemCost[' + i + '] * itemQty[' + i + ']);');
  371.     //document.shopCart.subtotal.value= fix(sub_total);
  372.      return + fix(sub_total);
  373.  }
  374. }
  375.  
  376. // ** Round to 2 decimal places**
  377. function fix(num) {
  378.  string = "" + num;
  379.  if (string.indexOf('.') == -1)
  380.   return string + '.00';
  381.  seperation = string.length - string.indexOf('.');
  382.  if (seperation > 3)
  383.   return string.substring(0,string.length-seperation+3);
  384.  else if (seperation == 2)
  385.   return string + '0';
  386.  return string;
  387. }
  388.  
  389. // ** Add carriage charge if necessary **
  390. function carriage(num) {
  391. if (num > 30) {
  392. return "";
  393. }
  394. if (num < 30) {
  395. return 2.5;
  396.  }
  397. }
  398.  
  399. function grand() {
  400.  if (getCookieData("Scart")) {
  401.   var up = update();
  402.   var car = eval('carriage(up)');
  403.   var gt = eval('up + car');
  404.  
  405.      return  fix(gt);
  406.  }
  407. }
  408.  
  409.  
  410. // **********************************************************************
  411. // *        Function to add  customer details and order details to the  *
  412. // *                              save form cookie                         *
  413. // *           When the form index display is written create unique name   *                                                            *
  414. // **********************************************************************
  415.  
  416. function saveform() {
  417.  
  418. var thedate = new Date();
  419. numdate = thedate.toLocaleString();
  420.  
  421. dataString = getCookieData("Scart")
  422. cLen = dataString.length
  423. countEnd = dataString.indexOf("@")
  424. pointer = countEnd + 1
  425. counter = dataString.substring(0,countEnd)
  426. counterD = counter
  427. scartData = dataString.substring(pointer,cLen)
  428.  
  429. dataString = getCookieData("Detail")
  430. cLen = dataString.length
  431. countEnd = dataString.indexOf("@")
  432. pointer = countEnd + 1
  433. counter = dataString.substring(0,countEnd)
  434. cusData = dataString.substring(pointer,cLen)
  435. cookData = '' + cusData + 'ó' + counterD + '@' + scartData + '^'
  436. counter = 0
  437. setCookieData(numdate,cookData,expdate.toGMTString())
  438.  
  439. //===========================================================
  440. if (getCookieData("fIndex")) {
  441. dataString = getCookieData("fIndex")
  442. cLen = dataString.length
  443. countEnd = dataString.indexOf("@")
  444. pointer = countEnd + 1
  445. counter = dataString.substring(0,countEnd)
  446. idxData = dataString.substring(pointer,cLen)
  447. idxData += eval("numdate + '^'");
  448. setCookieData("fIndex", idxData, expdate.toGMTString())
  449.  
  450. //detailInfo = '' + Salute + '¼' + FirstName 
  451. //        + '║' + Initials + '╗' + LastName + '┐' + CompName + '╢' + Address 
  452. //        + '▐' + Address2 + ' ' + PoCode + '°' +  CustTele  + '^'
  453.  
  454. } else {
  455.  
  456. counter = 0
  457. idxData = eval("numdate + '^'");
  458. setCookieData("fIndex", idxData, expdate.toGMTString())
  459.  
  460.   }
  461. history.go(0)
  462. }
  463.  
  464. // **********************************************************************
  465. // *            Builds an array of the items to load into the form.     *
  466. // **********************************************************************
  467.  
  468. function indexDetail(Idx,idxdetail) {
  469. formIndex[Idx]    = idxdetail
  470. }
  471. // -----------------------------  End  ----------------------------------
  472.  
  473. // **********************************************************************
  474. // *    Function to parse the cookie and extract the ordered            *
  475. // *                    items from the string.                           *
  476. // **********************************************************************
  477.  
  478. function displayIndex() {
  479.  
  480. if (getCookieData("fIndex")) {
  481.   substr0 = getCookieData("fIndex")
  482.   cLen = substr0.length
  483.   offset0 = substr0.indexOf("@")
  484.  
  485.   counter = substr0.substring(0,offset0)
  486.  
  487. j = 0
  488. for (i=1; i<=counter; i++) {
  489.  offsetq = eval('offset' + j + '');
  490.  substrq = eval('substr' + j + '');
  491.  
  492.   eval('ind' + i + ' = offsetq + 1');
  493.   eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  494.   eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  495.   eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  496.  
  497.   eval('indexDetail(i,item' + i + ')');
  498.   
  499.   j++
  500.   }
  501.  }
  502. }
  503.  
  504. // ** Function to load the index Variables  **
  505. // ** before writing the index
  506.  
  507. function showIndex() {
  508. displayIndex();
  509. writeIndex();
  510. }
  511.  
  512. // ** Function to load the index Variables  **
  513. // ** before writing the index
  514.  
  515. function showBasket() {
  516. itemsOrdered() ;
  517. writecheckout();
  518. }
  519.  
  520. // ** Function to write the shopping cart details **
  521. // ** into the table on the shopping cart page.
  522.  
  523.  
  524. function writeIndex() {
  525.  
  526.  var ordFrm  =  ' <form name="shopCart">'
  527.  ordFrm +=  '     <TABLE WIDTH="466" BGCOLOR="#000096" BORDER="1" BORDERCOLOR="#000096"'
  528.  ordFrm +=  '      CELLPADDING="0" CELLSPACING="0"> '
  529.  ordFrm +=  '        <TR> '
  530.  ordFrm +=  '          <TD BGCOLOR="#FFFFFF"> '
  531.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#000096" BORDER="0" CELLPADDING="0"'
  532.  ordFrm +=  '              CELLSPACING="0"> '
  533.  ordFrm +=  '                <TR VALIGN="TOP"> '
  534.  ordFrm +=  '                  <TD WIDTH="80" VALIGN="TOP" ALIGN="LEFT"><FONT'
  535.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF">'
  536.  ordFrm +=  '                     <B> Order<BR> Code</B></FONT></TD> '
  537.  ordFrm +=  '                  <TD WIDTH="326" VALIGN="TOP" ALIGN="LEFT"><FONT'
  538.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1"'
  539.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Description</B></FONT></TD> '
  540.  
  541.  ordFrm +=  '                  <TD VALIGN="TOP" ALIGN="LEFT" WIDTH="60"><FONT'
  542.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1"'
  543.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Remove </B></FONT></TD> '
  544.  ordFrm +=  '                </TR> '
  545.  ordFrm +=  '             </TABLE> '
  546.  
  547.  ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  548.  ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  549.  ordFrm +=  '                <TR> '
  550.  ordFrm +=  '                  <TD></TD> '
  551.  ordFrm +=  '                </TR> '
  552.  ordFrm +=  '             </TABLE> '
  553.  
  554.  
  555.   for (i = 1; i <= counter; i++) {
  556.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  557.  ordFrm +=  '              CELLSPACING="0"> '
  558. ordFrm += '        <TR> '
  559. ordFrm += '          <TD WIDTH="80"><FONT SIZE="1" FACE="Arial" COLOR="#FFFFCC"><A'
  560. ordFrm += '             HREF="javascript:extractOrder('+i+')"><IMG'
  561.  ordFrm +=  '                     SRC="showord.gif" WIDTH="75" HEIGHT="15" BORDER="0"></A></FONT></TD> '
  562. ordFrm += '          <TD><FONT SIZE="1" FACE="Arial" COLOR="#000033">Order of ' + formIndex[i] + '</FONT></TD> '
  563. ordFrm += '          <TD WIDTH="70" ALIGN="RIGHT"><FONT SIZE="1" FACE="Arial" COLOR="#FFFFCC"><A'
  564. ordFrm += '             HREF="javascript:clearIndex(' + i + ')"><IMG'
  565.  ordFrm +=  '        SRC="remove.gif" WIDTH="60" HEIGHT="15" BORDER="0"></A> </FONT></TD> '
  566. ordFrm += '        </TR> '
  567.  ordFrm +=  '             </TABLE> '
  568.   ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  569.   ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  570.   ordFrm +=  '                <TR> '
  571.   ordFrm +=  '                  <TD></TD> '
  572.   ordFrm +=  '                </TR> '
  573.   ordFrm +=  '             </TABLE> '
  574.  
  575.   }
  576.  
  577.   ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  578.   ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  579.   ordFrm +=  '                <TR> '
  580.   ordFrm +=  '                  <TD></TD> '
  581.   ordFrm +=  '                </TR> '
  582.   ordFrm +=  '             </TABLE> '
  583.  
  584. ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  585.  ordFrm +=  '              CELLSPACING="0"> '
  586.  ordFrm +=  '                <TR VALIGN="MIDDLE"> '
  587.  ordFrm +=  '                  <TD ALIGN="CENTER" VALIGN="MIDDLE" WIDTH="100%"><A'
  588.  ordFrm +=  '                     HREF="javascript:history.go(-1)"><IMG SRC="return.gif" WIDTH="60" HEIGHT="15"'
  589.  ordFrm +=  '                     BORDER="0"></A></TD> '
  590.  ordFrm +=  '                </TR> '
  591.  ordFrm +=  '             </TABLE> </TD> '
  592.  ordFrm +=  '        </TR> '
  593.  ordFrm +=  '     </TABLE>'
  594.   ordFrm += '</form> '
  595.   document.write(ordFrm);
  596.   document.close();
  597. }
  598.  
  599.  
  600.  
  601.  
  602. // ****End shopping cart detail section.****
  603.  
  604. // ****Start of code section to display subtotal.****
  605.  
  606. function update() {
  607.  if (getCookieData("Scart")) {
  608.   var sub_total = 0;
  609.   for (i=1; i<itemNum.length; i++)
  610.    eval('sub_total += parseFloat(itemCost[' + i + '] * itemQty[' + i + ']);');
  611.     //document.shopCart.subtotal.value= fix(sub_total);
  612.      return + fix(sub_total);
  613.  }
  614. }
  615. // ** Function to write the shopping cart details **
  616. // ** into the table on the shopping cart page.
  617.  
  618.  
  619. function writecheckout() {
  620.  
  621. var ordFrm  =  ' <BR> '
  622.  ordFrm +=  '     <FORM METHOD="post"'
  623.  ordFrm +=  '      ACTION="https://catalogue.maplin.co.uk/direct/CDEntry.asp" ID="form1"'
  624.  ordFrm +=  '    NAME="form1" Target="about:blank"> <INPUT TYPE="hidden" NAME="TotalItems" VALUE="' + counter + '"> '
  625.  ordFrm +=  '     <TABLE WIDTH="466" BGCOLOR="#000000" BORDER="1"BORDERCOLOR="#000096"'
  626.  ordFrm +=  '      CELLPADDING="0" CELLSPACING="0"> '
  627.  ordFrm +=  '        <TR> '
  628.  ordFrm +=  '          <TD BGCOLOR="#FFFFFF"> '
  629.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#000096" BORDER="0" CELLPADDING="0"'
  630.  ordFrm +=  '              CELLSPACING="0"> '
  631.  ordFrm +=  '                <TR VALIGN="TOP"> '
  632.  ordFrm +=  '                  <TD WIDTH="60" VALIGN="TOP" ALIGN="LEFT"><FONT'
  633.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF">'
  634.  ordFrm +=  '                     <B> Order<BR> Code</B></FONT></TD> '
  635.  ordFrm +=  '                  <TD WIDTH="140" VALIGN="TOP" ALIGN="LEFT"><FONT'
  636.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1"'
  637.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Description</B></FONT></TD> '
  638.  ordFrm +=  '                  <TD COLSPAN="2" WIDTH="60" VALIGN="TOP" ALIGN="CENTER"><FONT'
  639.  ordFrm +=  '                     COLOR="#FFFFFF" FACE="verdana,Arial,helvetica" SIZE="1"><B>Qty</B></FONT></TD> '
  640.  ordFrm +=  '                  <TD WIDTH="70" VALIGN="TOP" ALIGN="RIGHT"><FONT'
  641.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1" COLOR="#FFFFFF"><B>inc.VAT'
  642.  ordFrm +=  '                     <BR>each</B></FONT></TD> '
  643.  ordFrm +=  '                  <TD WIDTH="60" ALIGN="RIGHT" VALIGN="TOP"><FONT'
  644.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="-2"'
  645.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Total</B></FONT></TD> '
  646.  ordFrm +=  '                  <TD VALIGN="TOP" ALIGN="CENTER" WIDTH="80"><FONT'
  647.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1"'
  648.  ordFrm +=  '                     COLOR="#FFFFFF"><B>Remove</B></FONT></TD> '
  649.  ordFrm +=  '                </TR> '
  650.  ordFrm +=  '             </TABLE> '
  651.  
  652.  ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  653.  ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  654.  ordFrm +=  '                <TR> '
  655.  ordFrm +=  '                  <TD></TD> '
  656.  ordFrm +=  '                </TR> '
  657.  ordFrm +=  '             </TABLE> '
  658.  
  659.  
  660.   for (i = 1; i <= counter; i++) {
  661.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  662.  ordFrm +=  '              CELLSPACING="0"> '
  663.  ordFrm +=  '                <TR> '
  664.  ordFrm +=  '                  <TD WIDTH="60"><FONT FACE="verdana,Arial,helvetica" SIZE="-2"'
  665.  ordFrm +=  '                     COLOR="#330099"><B> ' + itemNum[i] + '</B></FONT></TD> '
  666.  ordFrm +=  '                  <TD WIDTH="140"><FONT FACE="verdana,Arial,helvetica"'
  667.  ordFrm +=  '                     SIZE="-2">' + itemDescr[i] + '</FONT></TD> '
  668.  ordFrm +=  '                  <TD WIDTH="45" ALIGN="CENTER"><FONT'
  669.  ordFrm +=  '                     FACE="verdana,Arial,helvetica" SIZE="1">' + itemQty[i] + '</FONT></TD> '
  670.  ordFrm +=  '                  <TD WIDTH="70" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  671.  ordFrm +=  '                     SIZE="-2">£' + itemCost[i] + '</FONT></TD> '
  672.  ordFrm +=  '                  <TD WIDTH="60" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  673.  ordFrm +=  '                     SIZE="-2">£' + fix(itemCost[i]  *  itemQty[i]) + '</FONT></TD> '
  674.  ordFrm +=  '                  <TD WIDTH="80" ALIGN="RIGHT"><A href="javascript:clearIt('+i+')"><IMG'
  675.  ordFrm +=  '                     SRC="remove.gif" WIDTH="60" HEIGHT="15" BORDER="0"></A></TD> '
  676.   
  677. ordFrm +=  '        <!-- Hidden Text Boxes to store code and quantity for submission -->'
  678.   ordFrm +=  '            <TR> '
  679.   ordFrm +=  '               <TD><INPUT TYPE="hidden" NAME="OrderCode' + i + '" MAXLENGTH="5" VALUE="' + itemNum[i] + '">'
  680.   ordFrm +=  '               <INPUT TYPE="hidden" NAME="Quantity' + i + '" MAXLENGTH="5" VALUE="' + itemQty[i] + '"> </TD> '
  681.   ordFrm +=  '            </TR> '
  682.   ordFrm +=  '        <!-- =========================================================== -->'
  683.  
  684.  ordFrm +=  '                </TR> '
  685.  ordFrm +=  '             </TABLE> '
  686.  
  687.   ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  688.   ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  689.   ordFrm +=  '                <TR> '
  690.   ordFrm +=  '                  <TD></TD> '
  691.   ordFrm +=  '                </TR> '
  692.   ordFrm +=  '             </TABLE> '
  693.  
  694.   }
  695.  
  696.  ordFrm +=  '             <TABLE WIDTH="466" BGCOLOR="#FEF0D8" BORDER="0" CELLPADDING="0"'
  697.   ordFrm +=  '              CELLSPACING="0"> '
  698.   ordFrm +=  '                <TR> '
  699.   ordFrm +=  '                  <TD WIDTH="60"> </TD> '
  700.   ordFrm +=  '                  <TD WIDTH="140"><FONT FACE="verdana,Arial,helvetica"'
  701.   ordFrm +=  '                     SIZE="-2" COLOR="#006400">Total Items = ' + counter + '</FONT></TD> '
  702.   ordFrm +=  '                  <TD WIDTH="45" ALIGN="CENTER"> </TD> '
  703.   ordFrm +=  '                  <TD WIDTH="70" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  704.   ordFrm +=  '                     SIZE="-2" COLOR="#000066">Sub Total</FONT></TD> '
  705.   ordFrm +=  '                  <TD WIDTH="60" ALIGN="RIGHT"><FONT FACE="verdana,Arial,helvetica"'
  706.   ordFrm +=  '                     SIZE="-2">£' + update() + '</FONT></TD> '
  707.   ordFrm +=  '                  <TD WIDTH="80" ALIGN="RIGHT"> </TD> '
  708.   ordFrm +=  '                </TR> '
  709.  
  710.   ordFrm +=  '             </TABLE>'
  711.   ordFrm +=  '             <TABLE WIDTH="466" BORDER="0" CELLPADDING="0"'
  712.   ordFrm +=  '              CELLSPACING="0" BGCOLOR="#FBCE82"> '
  713.   ordFrm +=  '                <TR> '
  714.   ordFrm +=  '                  <TD></TD> '
  715.  
  716.  
  717.  ordFrm +=  '            </TABLE> '
  718.  
  719.  ordFrm +=  '        </TD> '
  720.  ordFrm +=  '        </TR> '
  721.  ordFrm +=  '     </TABLE>'
  722.  
  723.   ordFrm += '</form> '
  724.   document.write(ordFrm);
  725.   document.close();
  726. }
  727. function clearIt(num) {
  728. if (confirm("Remove Qty " + itemQty[i] + " Code " + itemNum[i] + ' Description ' + itemDescr[i] )) {
  729. itemsOrdered();            //Refresh Variables and load Variable "counter"
  730. itemNum[num] = "item"
  731. rewriteCookie(counter)
  732. }
  733. }
  734.     
  735. // **Function to rewrite the cookie when the user **
  736. // **deletes a line item from the shopping cart. **
  737.  
  738. function rewriteCookie(num) {
  739.  
  740.  
  741.  
  742.  dataUpdate = ""
  743.  for (i=1; i<=counter; i++) {
  744.    if (itemNum[i] != "item") {
  745.     dataUpdate += itemNum[i] + '`' + itemDescr[i] + '~$' + itemCost[i] + '½' + itemQty[i] + '^'
  746.    }
  747.  }
  748.  counter = counter - 2
  749.  cookData = dataUpdate
  750.  expdate2.setTime (expdate.getTime() + (7 * 24 * 60 * 60 * 1000))
  751.  setCookieData("Scart", cookData, expdate2.toGMTString())
  752.  history.go(0)
  753. }    
  754.  
  755. // ** Function to delete an index item upon user request. **
  756.  
  757. // function clearIndex(num) {
  758. //  alert("Clear " + num)
  759. //   if (confirm("Remove order of " + num + ' ' + formIndex[num])) {
  760. //    alert("Confirmed " + num)
  761. //   formFile = formIndex[num]
  762. //    alert("FormFile " + num)
  763. //   killCookie(formFile)
  764. //    alert("Killed " + num)
  765. //   displayIndex()
  766. //    alert("Display " + num)
  767. // 
  768. //  formIndex[num] = "item"
  769. //   alert("Formindex " + num + " " + formIndex[num])
  770. //  rewriteIndex(num)
  771. // }
  772. //}
  773.  
  774. // **Function to rewrite the cookie when the user **
  775. // **deletes a line item from the index. **
  776.  
  777. //function rewriteIndex(num) { // Counter
  778. // alert("Rewrite " + num)
  779. // dataUpdate = ""
  780. // for (i=1; i<=counter; i++) {
  781. //    if (formIndex[i] != "item") {
  782. //    dataUpdate += formIndex[i] + '^' 
  783. //   }
  784. // }
  785. // counter = counter - 2
  786. // cookData = dataUpdate
  787. // setCookieData("fIndex", cookData, expdate.toGMTString())
  788. //  alert("Cookie Set " + num)
  789. // history.go(0)
  790. //}
  791.  
  792.  
  793. //function clearIt(num) {
  794. // itemNum[num] = "item"
  795. // rewriteCookie(num)
  796. //}
  797.  
  798. // **Function to rewrite the cookie when the user **
  799. // **deletes a line item from the shopping cart. **
  800.  
  801. //function rewriteCookie(num) {
  802. // dataUpdate = ""
  803. // for (i=1; i<=counter; i++) {
  804. //   if (itemNum[i] != "item") {
  805. //    dataUpdate += itemNum[i] + '`' + itemDescr[i] + '~$' + itemCost[i] + '½' + itemQty[i] + '^'
  806. //   }
  807. // }
  808. // counter = counter - 2
  809. // cookData = dataUpdate
  810. // setCookieData("Scart", cookData, expdate.toGMTString())
  811. // history.go(0)
  812. //}
  813.  
  814. // ** Function to delete index & Form items upon user request. **
  815.  
  816.  function clearIndex(num) {
  817.        if (confirm("Remove order of " + num + ' ' + formIndex[num])) {
  818.     formFile = formIndex[num]
  819.     formIndex[num] = "item"
  820.  
  821.        displayIndex();
  822.      dataUpdate = ""
  823.      for (i=1; i<=counter; i++) {
  824.         if (i != num) {
  825.         dataUpdate += formIndex[i] + '^' 
  826.        }
  827.      }
  828.      counter = counter - 2
  829.      cookData = dataUpdate
  830.      setCookieData("fIndex", cookData, expdate.toGMTString())
  831.      killCookie(formFile)
  832.  history.go(0)
  833.  }
  834. }
  835.  
  836.